package 算法.图.util;

import javax.management.RuntimeErrorException;

import com.sun.org.apache.regexp.internal.recompile;

/**
 * 【无向图：带权重的边】
 * 
 * @Date   2017-09-03
 * @author Administrator
 * @version 
 */
public class Edge implements Comparable<Edge> {
	public int v, w;		//当前边的两个顶点(因为是无向图，顶点顺序无所谓)
	public double weight;	//权重
	public Edge(int v, int w, double weight) {
		this.v = v;
		this.w = w;
		this.weight = weight;
	}

	//返回其中一个顶点
	public int either() {
		return v;
	}
	
	//返回另一个顶点
	public int other(int vertex) {
		if (vertex == v)	return w;
		if (vertex == w)  return v;
		throw new RuntimeException("没有你要找的边");
	}
	
	//边的权重比较
	public int compareTo(Edge that) {
		if	   (this.weight < that.weight)	return -1;
		else if(this.weight > that.weight)	return  1;
		else 								return  0;
	}
	
	@Override
	public String toString() {
		return "Edge [v=" + v + ", w=" + w + ", weight=" + weight + "]";
	}
}
